package nowcoder.day_48.day7;

import java.util.Scanner;
import java.util.Stack;

public class Num2 {
    public boolean chkParenthesis(String A, int n) {
        if (n % 2 != 0)return false;
        Stack<Character> stack = new Stack<>();
        for (char ch : A.toCharArray()){
            if (ch == '('){
                stack.push(ch);
            }else if (ch == ')'){
                if (stack.isEmpty()){
                    return false;
                }else if (stack.peek() == '('){
                    stack.pop();

                }
            }else {
                return false;
            }
        }
        return stack.isEmpty();
    }


}
